package Day2025_03_31;

public class LeetCode129 {
    public int sumNumbers(TreeNode root) {
        return sumNumberss(root, 0);
    }
    private int sumNumberss (TreeNode root, int ret) {
        if (root == null) return 0;
        if (root.left == null && root.right == null) return ret * 10 + root.val;
        int tmp = ret * 10 + root.val;
        int left = sumNumberss(root.left, tmp);
        int right = sumNumberss(root.right, tmp);
        return left + right;
    }
}
